package week6;

import java.util.Arrays;
import java.util.Scanner;

public class Main01
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.nextLine());
		Person[] persons=new Person[n];
		for (int i = 0; i < n; i++) 
		{
			persons[i] = new Person(in.next(), in.nextInt());
		}
		Arrays.sort(persons,
				(o1,o2)->{
					if(!o1.name.equals(o2.name))
						return o1.name.compareTo(o2.name);
					return o2.age-o1.age; 
				});
		for (Person e : persons) 
		{
			System.out.println(e);
		}
	}
}

class Person1
{
	String name;
	int age;

	public Person(String name,int age)
	{
		this.name=name;
		this.age=age;
	}
	public String toString() 
	{
		return name+"-"+age;
	}
}